﻿using System;
using System.Windows;
using DSPL.Services;
using DSPL.Contracts;
using DSPL.Common;
using System.Data;
using DSPL.Services.Services;
using DSPL.Contracts.Common;
using DSPL.Contracts.ViewModel;
using DSPL.Contracts.Command;
using DSPL.Finac.Common;
using System.Windows.Input;

namespace DSPL.Finac.ViewModel
{
    public class CardTypeMasterViewModel : BaseViewModel
    {
        private bool isCardCodeFocused;
        private bool isCardNameFocused;       
      
       
        #region Define properties

        public bool IsCardCodeFocused
        {
            get { return isCardCodeFocused; }
            set
            {
                isCardCodeFocused = value;
                this.OnPropertyChanged("IsCardCodeFocused");
            }
        }
               
        public bool IsCardNameFocused
        {
            get { return isCardNameFocused; }
            set
            {
                isCardNameFocused = value;
                this.OnPropertyChanged("IsCardNameFocused");

            }
        }             

        #endregion

       
        #region Constructor

        public CardTypeMasterViewModel()
            : base()
        {
            MessageTitle = "Card Type Master";
        }

        #endregion
        /// <summary>
        /// Validate mandatory data before save
        /// </summary>
        /// <param name="obj"></param>
        protected override void PreDataValidateExecuted(object obj)
        {
            IsCardCodeFocused = false;
            IsCardNameFocused = false;
           
            var messageService = new MessageService();
            if (CurrentRow["CrdTypCode"].ToString().Trim() == string.Empty)
            {
                messageService.ShowMessage(MessageText.CardTypeNotEmpty, MessageTitle, MessageType.InfoOK);
                IsCardCodeFocused = true;
                this.IsValid = false;
                return;
            }

            if (CurrentRow["CrdTypName"].ToString().Trim() == string.Empty)
            {
                messageService.ShowMessage(MessageText.CardNameNotEmpty, MessageTitle, MessageType.InfoOK);
                IsCardNameFocused = true;
                this.IsValid = false;
                return;
            }
                       
            this.IsValid = true;
        }

        protected override void RefreshExternalDataObjectsExecueted(object obj)
        {

            base.RefreshExternalDataObjectsExecueted(obj);

            if (FormMode == Modes.New)
            {
                
                CurrentRow["Active"] =1 ;
                OnPropertyChanged("CurrentRow");
               
            }

        }
                
    }
}